<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>09_节流-this-参数绑定</title>
</head>
<body>

  <button>按钮</button>

  <input type="text">

  <script>
    function throttle(fn, interval) {
      let startTime = 0
      const _throttle = function (...args) {
        const nowDate = new Date().getTime()
        const waitTimeFlag = nowDate - startTime >= interval
        if (waitTimeFlag) {
          fn.apply(this, args)
          startTime = nowDate
        }
      }
      return _throttle
    }

    const inputEl = document.querySelector("input")
    let counter = 1
    inputEl.oninput = throttle(function (event) {
      console.log(`发送了第${counter++}次网络请求`, this.value, event)
    }, 1000)

  </script>
  
</body>
</html>